<template>
    <div class="szzsDes">
        <h1>上证指数当前数值: {{ currentValue }}</h1>
        <table>
            <thead>
                <tr>
                    <th>对比情况</th>
                    <th>突破数值时间</th>
                    <th>突破数值的值</th>
                    <th>经过天数</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>上一次</td>
                    <td>{{ lastReachDate }}</td>
                    <td>{{ lastReachValue }}</td>
                    <td>{{ lastDaysPassed }}</td>
                </tr>
                <tr>
                    <td>上上次</td>
                    <td>{{ secondLastReachDate }}</td>
                    <td>{{ secondLastReachValue }}</td>
                    <td>{{ secondLastDaysPassed }}</td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script>
export default {
    data() {
        return {
            currentValue: 0,
            lastReachDate: '无记录',
            lastReachValue: '无记录',
            lastDaysPassed: '无记录',
            secondLastReachDate: '无记录',
            secondLastReachValue: '无记录',
            secondLastDaysPassed: '无记录'
        };
    },
    props: {
        szzs_list: {
            type: Array,
            default: [],
            required: true
        },  
        szzs_time: {
            type: Array,
            default: [],
            required: true
        },
    },
    created() {
        let data1 = this.szzs_list
        //[3200, 3330, 3430, 3100, 3200, 3420, 3200, 3000, 3400];
        let time = this.szzs_time
        //['2024-01-01', '2024-02-01', '2024-03-05', '2024-06-01', '2024-07-01', '2024-08-01', '2024-09-01', '2024-09-11', '2024-09-15'];
        this.currentValue = 3400;

        let lastIndex = -1;
        let secondLastIndex = -1;
        for (let i = data1.length - 2; i >= 0; i--) {
            if (data1[i] >= this.currentValue) {
                if (lastIndex === -1) {
                    lastIndex = i;
                } else {
                    secondLastIndex = i;
                    break;
                }
            }
        }

        this.lastDaysPassed = lastIndex === -1? '无记录' : data1.length - 1 - lastIndex;
        this.lastReachDate = lastIndex === -1? '无记录' : time[lastIndex];
        this.lastReachValue = lastIndex === -1? '无记录' : data1[lastIndex];

        this.secondLastDaysPassed = secondLastIndex === -1? '无记录' : data1.length - 1 - secondLastIndex;
        this.secondLastReachDate = secondLastIndex === -1? '无记录' : time[secondLastIndex];
        this.secondLastReachValue = secondLastIndex === -1? '无记录' : data1[secondLastIndex];
    }
};
</script>

<style scoped>
.szzsDes{
    margin-top: 30px;
}
table {
    border-collapse: collapse;
    width: 100%;
}

th,
td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

th {
    background-color: #f2f2f2;
}
</style>    